package worldinruin.core.imp;

import java.util.LinkedList;
import java.util.List;

import worldinruin.core.IGame;
import worldinruin.core.IMap;
import worldinruin.core.IPlayer;

public class Game implements IGame {

	private LinkedList<IPlayer> players;
	private IMap map;
	
	/**
	 * Creates a gameobject to be used for the game session.
	 * @param players Players playing the game.
	 * @param map Map used for the game.
	 */
	public Game(List<IPlayer> players, IMap map){
		this.players = new LinkedList<IPlayer>(players);
		this.map = map;
	}	

	/* (non-Javadoc)
	 * @see worldinruin.core.imp.IGame#getPlayers()
	 */
	public List<IPlayer> getPlayers() {
		return players;
	}

	/* (non-Javadoc)
	 * @see worldinruin.core.imp.IGame#getMap()
	 */
	public IMap getMap() {
		return map;
	}
	
	/* (non-Javadoc)
	 * @see worldinruin.core.imp.IGame#getActivePlayer()
	 */
	public IPlayer getActivePlayer(){
		return players.getFirst();
	}
	
	
	/* (non-Javadoc)
	 * @see worldinruin.core.imp.IGame#setActivePlayer(worldinruin.core.IPlayer)
	 */
	public void setActivePlayer(IPlayer player) {
		if(players.contains(player)) {
			while(players.getFirst() != player) {
				setActivePlayer();
			}
		}
	}
	
	/* (non-Javadoc)
	 * @see worldinruin.core.imp.IGame#setActivePlayer()
	 */
	public void setActivePlayer() {
		players.addLast(players.removeFirst());
	}
	
}
